﻿/*  ----------------------------------------------------------------------------
 *  SysServer
 *  ----------------------------------------------------------------------------
 *  File:       DisposableEntity.cs
 *  Creater:     SEEN\MistSeen
 *  ----------------------------------------------------------------------------
 *  $Date: 2010-09-06 10:36:01 +0000 (Mon, 06 Sep 2010) $
 *  $Rev: 15 $
 *  $Author: ScorDeity $
 *  $URL: http://sysserver.googlecode.com/svn/trunk/src/SysServer/DisposableEntity.cs $
 *  $Id: DisposableEntity.cs 15 2010-09-06 10:36:01Z ScorDeity $
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace SysServer
{
    public abstract class DisposableEntity : IDisposable
    {
        private int _Disposed = 0;
        protected virtual bool IsDisposed
        {
            get { return this._Disposed == 1; }
        }

        protected virtual void Dispose(bool disposing)
        {

        }

        #region IDisposable 成员

        public void Dispose()
        {
            if (Interlocked.Exchange(ref this._Disposed, 1) == 1)
            {
                return;
            }
            GC.SuppressFinalize(this);
            Dispose(true);
        }


        #endregion
        /// <summary>
        /// 
        /// </summary>
        ~DisposableEntity()
        {
            Dispose(false);
        }

    }
}